from functools import wraps

import aiohttp
import asyncio


def wrapper(func):
    @wraps(func)
    async def wrapper(*args, err, **kwargs):
        result = await asyncio.create_task(func(*args, **kwargs))	# 执行传入的函数
        # print(result)
        if not result:
            print(err)
        return result

    return wrapper


@wrapper
async def get_message(session):
    # print('开始访问')
    async with session.get('https://www.baidu.com') as response:
        # print('访问结束')
        return await response.text()


async def run():
    async with aiohttp.ClientSession() as session:
        return await asyncio.create_task(get_message(session, err='not'))	# 将功能函数加入任务列表


if __name__ == '__main__':
    s = asyncio.run(run())